#pragma once

#include "file_def.h"
#include "FileReader.h"

class VariableSizeBinFileReader
{
public:
	VariableSizeBinFileReader();
	virtual ~VariableSizeBinFileReader();

	bool Init(IN stringc& strBinFile, IN u32 binUseMemory, IN u32 offsetUseMemory, IN u32 readFlag);
	void Uninit();
	
	u32 GetRecordNum();
	bool GetRecordFromIndex(IN u32 index, OUT void* pRecord);

protected:
	virtual _BIN_FILE_RESULT GetRecordFromOffset(INOUT FileReader* pfr, IN u64 offset, OUT void* pRecord, OUT u32* pSize) = 0;

protected:
	void Clear();
	bool ConvertIndexToOffset(IN u32 index, OUT u64& offset);
	bool GenerateOffsetFile();
	bool GetOffsetInfo();

private:
	// parameter
	string m_strBinFile, m_strOffsetFile;
	u32 m_binUseMemory;
	u32 m_offsetUseMemory;
	u32 m_readFlag;

	//
	FileReader* m_pBinFile;
	u64 m_binFileSize;

	FileReader* m_pOffsetFile;
	u32 m_recordNum;
	u32 m_maxRecordSize;

	u32 m_innerFlag;

};